<template>
  <div style="width: 100%">
    <a-card class="card" :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="抽查条件">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.cctj">
                  <a-select-option v-for="i in selectCctjConfig" :key="i.code" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="年级">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.nj">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
             <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" v-if="queryParam.cctj==1">
                <a-form-item label="抽取人数">
                  <a-input-number :min="1"  v-model="queryParam.cqrs" />
                </a-form-item>
              </a-col>
            <template v-if="queryParam.cctj==2">
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="院系">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.yx" @change="handleSelectYx">
                    <a-select-option v-for="i in selectYxConfig" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="专业">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                    <a-select-option v-for="i in selectZyConfig" :key="i.zyh" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <!-- <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="姓名">
                  <a-input placeholder="请输入..." v-model="queryParam.xm" />
                </a-form-item>
              </a-col> -->
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="导师姓名">
                  <a-input placeholder="请输入..." v-model="queryParam.dsxm" />
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="学号尾号">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.xhwh">
                    <a-select-option v-for="i in [0,1,2,3,4,5,6,7,8,9]" :key="i" :value="i">{{ i }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <!-- <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="学生类别">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.xslb">
                    <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col> -->
            </template>
            <a-col :sm="{span:24}" :xl="24" style="text-align:center">
              <a-button type="primary" @click="handleLoad">抽查</a-button>
              <a-button type="primary" @click="handleExport">导出</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card>
      <!-- <STable ref="table" rowKey="xh" size="default" :alert="options.alert" :rowSelection="options.rowSelection" :pageSize="pageSize" :columns="columns" :data="loadData">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <a slot="operation" slot-scope="text, record, index" @click="handleOpenEdit(record)">修改</a>
      </STable> -->
    <a-table ref="table" rowKey="xh" :loading="loading" size="default" :columns="columns" :dataSource="data" :pagination="false" >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </a-table>
    </a-card>
  </div>
</template>
<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'


const selectArr = [
  'TYPE0126', //年级
  'TYPE0075' //学生类别
]

export default {
  components: {
    STable
  },
  data() {
    return {
      data:[],
      loading:false,
      // 条件配置
      selectCctjConfig:[{
        code:1,
        name:'随机抽查'
      },{
        code:2,
        name:'条件抽查'
      }],//抽取条件
      selectYxConfig: [], //院系
      selectZyConfig: [], //专业
      // 查询参数
      queryParam: {
        cctj:1,
        cqrs:1,
      },
      postParams: {},
      // 表头
      columns: [{
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '院系',
          dataIndex: 'ssyxmc'
        },
        {
          title: '专业',
          dataIndex: 'sszymc'
        },
        {
          title: '导师',
          dataIndex: 'dsxm'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.$nextTick(() => {
          this.selectedRowKeys = []
          this.$refs.table.clearSelected()
        })
        let params = Object.assign({},this.queryParam)
        return this.$api.degree.paperSpotCheck(params).then(res => {
          this.pageSize = res.data.length;
          return {
            data: res.data,
            pageNo: parameter.pageNo,
            totalCount:0
          }
        })
      },
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0075: state => state.app['TYPE0075'], // 学生类别
      TYPE0126: state => state.app['TYPE0126'], // 年级
    })
  },
  created() {
    this.initSelectMenu()

    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.handleLoad();
  },
  methods: {
    initSelectMenu() {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectYxConfig = res[0].data
      })
    },
    //抽查
    handleLoad(){
      let params = this.queryParam;
      this.loading = true;
      this.$api.degree.paperSpotCheck(params).then(res => {
          this.data = res.data;
          this.loading = false;
        })
    },
    //选择院系
    handleSelectYx(code) {
      this.selectZyConfig = [];
      this.$set(this.queryParam,'zy','');
      this.$api.base.majorAll({ lsdwh: code }).then(res => {
        this.selectZyConfig = res.data;
      })
    },
    //导出
    handleExport() {
      this.$export('/degree/xwlwxx/lwccExp', {
        xhs:this.data.map(e=>(e.xh)).join(",")
      })
    }
  }
}

</script>
<style lang="less" scoped>
.card {
  margin-bottom: 20px;
}

</style>
